package com.itheima.blog.article.controller;

import com.itheima.blog.article.entity.TAlbum;
import com.itheima.blog.article.service.ITAlbumService;
import com.itheima.common.domain.PageReqDto;
import com.itheima.common.domain.PageResDto;
import com.itheima.common.domain.R;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 用户相册表 前端控制器
 * </p>
 *
 * @author lin
 * @since 2023-07-12
 */
@RestController
@RequestMapping("/owner/album")
@RequiredArgsConstructor
public class TAlbumController {

    private final ITAlbumService itAlbumService;

    @PostMapping("/upload")
    @ApiOperation("上传图片")
    public R uploadAlbumPicture(@RequestPart("file") MultipartFile file){
        String s = itAlbumService.uploadBannerPicture(file);
        return R.ok(s);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除图片")
    public R deleteAlbumById(@RequestParam("ids") List<Long> ids){
        itAlbumService.deleteBannerById(ids);
        return R.ok();
    }

    @GetMapping("/list")
    @ApiOperation("列表展示")
    public PageResDto<TAlbum> findPage(PageReqDto pageReqDto){
        return itAlbumService.findPage(pageReqDto);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询轮播图")
    public R<TAlbum> findAlbumById(@PathVariable("id") Long id){
        return itAlbumService.findAlbumById(id);
    }

    @PostMapping("/{id}")
    @ApiOperation("根据id剪裁(编辑图片，替换)")
    public void updateById(@PathVariable("id") Long id,@RequestPart("file") MultipartFile file){
        itAlbumService.updateFile(id,file);
    }
}
